package com.layui.ad.utils;

import com.layui.ad.config.shiro.entiry.ShiroUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

public class ShiroUtils {
    /**
     * 私有构造器
     **/
    private ShiroUtils() {
    }


    /**
     * 获取当前用户Session
     *
     * @return
     */
    public static Session getSession() {
        return SecurityUtils.getSubject().getSession();
    }

    /**
     * 用户退出
     */
    public static void logout() {
        SecurityUtils.getSubject().logout();
    }

    /**
     * 获取当前用户信息
     *
     * @return
     */
    public static ShiroUser getAdminInfo() {
        return (ShiroUser) SecurityUtils.getSubject().getPrincipal();
    }

    /**
     * 获取用户编号
     *
     * @return
     */
    public static Integer getAdminId() {
        ShiroUser admin = getAdminInfo();
        return admin.getUserId();
    }
}
